package logic

import (
	"api/pkg"
	"cart_srv/cart_srv"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateCartLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCartLogic {
	return &CreateCartLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateCartLogic) CreateCart(req *types.CreateCartRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	cart, err := l.svcCtx.CartSrv.CreateCart(l.ctx, &cart_srv.CreateCartRequest{
		UserId: int64(req.UserId),
		ShopId: int64(req.ShopId),
		Num:    int64(req.Num),
	})
	if err != nil {
		return &types.Response{
			Message: pkg.Sting(err.Error()),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "购物车添加成功",
		Code:    200,
		Data:    cart,
	}, nil
}
